// pages/andon/material_del/material_del.js
const behavior = getApp().require("behaviors/requests.js")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [behavior],
  data: {
    mopPicker: false,
    factoryPicker: false,
    factories: ["西区家用总装", "东区家用总装", "商用总装", "中山基地"],
    other_name: ["west", "east", "ShangY", "ZhongS"],
    mop_ids: [],
    factory: '',
    mop_id: ''
  },

  showFactoryPicker() {
    this.setData({
      factoryPicker: true
    })
  },

  showMopPicker() {
    this.setData({
      mopPicker: true
    })
  },

  onConfirmFactory(event) {
    const { value, index } = event.detail;
    const that = this
    this.setData({
      "factory": value,
      mop_id: "",
      factoryPicker: false
    });
    const url = 'https://logisticsengineering.gree.com/andon_system/get_mobile_id_list';
    const data = {
      factory: that.data.factory
    };
    this.get(url, data).then((res) => {
      console.log(res)
      wx.showToast({
        title: res.msg,
      })
      that.setData({
        mop_ids: res.data
      })
    }).catch((err) => {
      console.log(err)
    })
  },

  onConfirmMop(event) {
    const value = event.detail.value
    this.setData({
      mop_id: value,
      mopPicker: false
    })
  },

  cancel_factoryPicker() {
    this.setData({
      factoryPicker: false
    })
  },

  cancel_mopPicker() {
    this.setData({
      mopPicker: false
    })
  },

  onSubmit() {
    const that = this;
    const url = 'https://logisticsengineering.gree.com/andon_system/del_mobile_id';
    const data = {
      factory: that.data.factory,
      mop_id: that.data.mop_id
    }
    this.get(url, data).then((res) => {
      console.log(res)
      wx.showToast({
        title: res.msg,
      })
    }).catch((err) => {
      console.log(err)
    })
  },

  getFactories() {
    const that = this;
    const url = "https://logisticsengineering.gree.com/andon_system/get_factory_list";
    this.get(url).then((res) => {
      that.setData({
        factories: res.data
      })
      console.log(res)
    }).catch((err) => {
      console.log(err)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getFactories();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})